

export default {

    data: {
        pageIndex: 1,
        count: 10,
        total: -1,
        arrArrData: '', // 二维数组
        isLoading: false,
        numTotal: -1, // 加载的 total
    },

    handleRefresh (callback) {
        this.setData({ pageIndex: 1 });
        this.reqDataList(callback);
    },

    reqDataList (callback) {
        this.setData({ isLoading: true });
        let {
            url,
            params = {},
            options = {},
        } = this.getUrlParamsOptions();
        let {
            pageIndex,
            count,
            arrArrData,
            numTotal,
        } = this.data;
        this.httpRequest(url, {
            pageIndex,
            count,
            ...params,
        }, {
            loading: false,
            ...options,
        }).then((res) => {
            let { total = 0, list = [] } = res || {};
            if (pageIndex === 1) {
                arrArrData = [];
                numTotal = 0;
                numTotal += list.length;
                arrArrData[0] = list;
                this.setData({
                    numTotal,
                    total,
                    arrArrData,
                });
            } else {
                numTotal += list.length;
                this.setData({
                    numTotal,
                    total,
                    [`arrArrData[${pageIndex - 1}]`]: list
                });
            }
        }).toast().finally(() => {
            this.setData({ isLoading: false });
            typeof callback === 'function' && callback();
        });
    },

    handleLoad () {
        let { pageIndex, total, arrArrData, numTotal, isLoading } = this.data;
        if (isLoading) {
            return console.log('正在加载中...');
        }
        if (arrArrData && total <= numTotal) {
            return console.log('没有更多了...');
        }
        pageIndex++;
        this.setData({ pageIndex });
        this.reqDataList();
    },

}
